﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Newtonsoft.Json.Linq;

namespace CLDataAppManagement
{
    public class DataAppManagement
    {
        private JToken _jToken;
        private string _filePath;

        public JToken LoadFile(string filePath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                string jsonText;
                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    //编码使用UTF8，GB2312有出现乱码的情况
                    using (StreamReader streamReader = new StreamReader(fs, Encoding.UTF8))
                    {
                        jsonText = streamReader.ReadToEnd();
                    }
                }
                _jToken = JToken.Parse(jsonText);
                this._filePath = filePath;

                return _jToken;
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "LoadFile Fail！" + ex.ToString();
                return null;
            }
        }

        public void SaveFile(string filePath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                string jsonData = _jToken.ToString(Newtonsoft.Json.Formatting.Indented);
                using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    using (StreamWriter streamWriter = new StreamWriter(fs))
                    {
                        streamWriter.Write(jsonData);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "SaveFile Fail！" + ex.ToString();
            }
        }

        public void SaveFile(string filePath, JToken jToken, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                string jsonData = jToken.ToString(Newtonsoft.Json.Formatting.Indented);
                using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    using (StreamWriter streamWriter = new StreamWriter(fs))
                    {
                        streamWriter.Write(jsonData);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "SaveFile Fail！" + ex.ToString();
            }
        }

        //******************************************************   以下测试可用   *************************************************************************

        public void ModifyKey(string sourcePath, string newKey, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                string[] keys = sourcePath.Split('.');
                string oldKey = keys[keys.Length - 1];
                string nodeName = sourcePath.Substring(0, sourcePath.LastIndexOf('.'));

                JToken nodeToken = GetParentToken(sourcePath, out ErrorCode, out ErrorText);

                var key = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);
                if (key.Contains("["))
                {
                    //数组以[ * : * ]  第一个* 是索引  第二个* 是给索引对应的名称
                    int index = int.Parse(key.Replace("[", "").Replace("]", "").Split(':')[0]);
                    string name = key.Replace("[", "").Replace("]", "").Split(':')[1];
                    foreach (JObject item in nodeToken.Children<JObject>())
                    {
                        if (item.ContainsKey(name))
                        {
                            JToken value = item[name];
                            item.Remove(name);
                            item[newKey] = value;
                        }
                    }
                }
                else
                {
                    JObject jt = new JObject();
                    foreach (var item in nodeToken.Children<JProperty>())
                    {
                        //if (item.Type == JTokenType.Array)
                        //{

                        //}
                        //else if (item.Type == JTokenType.Property)
                        //{
                        if (item.Name == key)
                        {
                            jt.Add(newKey, item.Value);
                        }
                        else
                        {
                            jt.Add(item);
                        }
                        //}
                    }
                    var nodeTokenParent = (JProperty)nodeToken.Parent;
                    nodeTokenParent.Value = jt;
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "ModifyKey Fail！" + ex.ToString();
            }
        }

        public void ModifyValue(string sourcePath, JToken newValue, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jt = GetParentToken(sourcePath, out ErrorCode, out ErrorText);
                var key = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);

                if (key.Contains("["))
                {
                    if (key.Contains(":"))
                    {
                        int index = int.Parse(key.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = key.Replace("[", "").Replace("]", "").Split(':')[1];
                        if (jt.Type == JTokenType.Array)
                        {
                            jt[index][name] = newValue;
                        }
                        else
                        {
                            foreach (var item in jt.Children<JProperty>())
                            {
                                if (item.Name == name)
                                {
                                    item.Value = newValue;
                                }
                            }
                        }
                    }
                    else
                    {
                        int index = int.Parse(key.Replace("[", "").Replace("]", ""));
                        jt[index] = newValue;
                    }
                }
                else
                {
                    jt[key] = newValue;
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "ModifyValue Fail！" + ex.ToString();
            }
        }

        public void AddKeyValue(string sourcePath, JToken newValue, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jt = GetParentToken(sourcePath, out ErrorCode, out ErrorText);
                var key = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);

                if (key.Contains("["))
                {
                    if (key.Contains(":"))
                    {
                        int index = int.Parse(key.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = key.Replace("[", "").Replace("]", "").Split(':')[1];
                        if (jt.Type == JTokenType.Array)
                        {
                            ((JArray)jt).Add(newValue);
                        }
                        else if (jt.Type == JTokenType.Object)
                        {
                            ((JObject)jt).Add(key, newValue);
                        }
                    }
                    else  //数组值
                    {
                        ((JArray)jt).Add(newValue);
                    }
                }
                else
                {
                    ((JObject)jt).Add(key, newValue);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "AddKeyValue Fail！" + ex.ToString();
            }
        }

        public void DeleteKeyValue(string sourcePath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jt = GetParentToken(sourcePath, out ErrorCode, out ErrorText);
                var key = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);

                if (key.Contains("["))
                {
                    if (key.Contains(":"))
                    {
                        int index = int.Parse(key.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = key.Replace("[", "").Replace("]", "").Split(':')[1];
                        if (jt.Type == JTokenType.Array)
                        {
                            ((JArray)jt)[index].Remove();
                        }
                        else if (jt.Type == JTokenType.Object)
                        {
                            ((JObject)jt)[index].Remove();
                        }
                    }
                    else  //数组值
                    {
                        int index = int.Parse(key.Replace("[", "").Replace("]", ""));
                        ((JArray)jt)[index].Remove();
                    }
                }
                else
                {
                    ((JObject)jt).Remove(key);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "DeleteKeyValue Fail！" + ex.ToString();
            }
        }

        public void CopyToBeforeDes(string sourcePath, string desPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jtSource = GetParentToken(sourcePath, out ErrorCode, out ErrorText);
                var keySource = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);
                JToken clone = null;
                if (keySource.Contains("["))
                {
                    if (keySource.Contains(":"))
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keySource.Replace("[", "").Replace("]", "").Split(':')[1];
                        //克隆数据
                        clone = ((JArray)jtSource)[index].DeepClone();
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", ""));
                        clone = ((JArray)jtSource)[index].DeepClone();
                    }
                }
                else
                {
                    clone = ((JObject)jtSource)[keySource].Parent.DeepClone();
                }
                JToken value = null;
                JToken jtDes = GetParentToken(desPath, out ErrorCode, out ErrorText);
                var keyDes = desPath.Substring(desPath.LastIndexOf(".") + 1);
                if (keyDes.Contains("["))
                {
                    if (keyDes.Contains(":"))
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keyDes.Replace("[", "").Replace("]", "").Split(':')[1];
                        ((JArray)jtDes)[index].AddBeforeSelf(clone);
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", ""));
                        ((JArray)jtDes)[index].AddBeforeSelf(clone);
                    }
                }
                else
                {
                    var jtParent = ((JObject)jtDes)[keyDes].Parent;
                    string name = ((JProperty)clone).Name;
                    CheckNameValid(jtDes, ref name, out ErrorCode, out ErrorText);
                    value = ((JProperty)clone).Value;
                    JProperty jProperty = new JProperty(name, value);
                    jtParent.AddBeforeSelf(jProperty);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "CopyToBeforeDes Fail！" + ex.ToString();
            }
        }

        public void CopyToAfterDes(string sourcePath, string desPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jtSource = GetParentToken(sourcePath, out ErrorCode, out ErrorText);
                var keySource = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);
                JToken clone = null;
                if (keySource.Contains("["))
                {
                    if (keySource.Contains(":"))
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keySource.Replace("[", "").Replace("]", "").Split(':')[1];
                        clone = ((JArray)jtSource)[index].DeepClone();
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", ""));
                        clone = ((JArray)jtSource)[index].DeepClone();
                    }
                }
                else
                {
                    clone = ((JObject)jtSource)[keySource].Parent.DeepClone();
                }


                JToken value = null;
                JToken jtDes = GetParentToken(desPath, out ErrorCode, out ErrorText);
                var keyDes = desPath.Substring(desPath.LastIndexOf(".") + 1);
                if (keySource.Contains("["))
                {
                    if (keySource.Contains(":"))
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keySource.Replace("[", "").Replace("]", "").Split(':')[1];
                        ((JArray)jtDes)[index].AddAfterSelf(clone);
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", ""));
                        ((JArray)jtDes)[index].AddAfterSelf(clone);
                    }
                }
                else
                {
                    var jtParent = ((JObject)jtDes)[keySource].Parent;
                    string name = ((JProperty)clone).Name;
                    CheckNameValid(jtDes, ref name, out ErrorCode, out ErrorText);
                    value = ((JProperty)clone).Value;
                    JProperty jProperty = new JProperty(name, value);
                    jtParent.AddAfterSelf(jProperty);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "CopyToAfterDes Fail！" + ex.ToString();
            }

        }

        public void MoveToAfterDes(string sourcePath, string desPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jtSource = GetParentToken(sourcePath, out ErrorCode, out ErrorText);
                var keySource = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);
                JToken clone = null;
                if (keySource.Contains("["))
                {
                    if (keySource.Contains(":"))
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keySource.Replace("[", "").Replace("]", "").Split(':')[1];
                        clone = ((JArray)jtSource)[index].DeepClone();
                        ((JArray)jtSource)[index].Remove();
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", ""));
                        clone = ((JArray)jtSource)[index].DeepClone();
                        ((JArray)jtSource)[index].Remove();
                    }
                }
                else
                {
                    clone = ((JObject)jtSource)[keySource].Parent.DeepClone();
                    ((JObject)jtSource)[keySource].Parent.Remove();
                }



                JToken value = null;
                JToken jtDes = GetParentToken(desPath, out ErrorCode, out ErrorText);
                var keyDes = desPath.Substring(desPath.LastIndexOf(".") + 1);
                if (keyDes.Contains("["))
                {
                    if (keyDes.Contains(":"))
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keyDes.Replace("[", "").Replace("]", "").Split(':')[1];
                        ((JArray)jtDes)[index].AddAfterSelf(clone);
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", ""));
                        ((JArray)jtDes)[index].AddAfterSelf(clone);
                    }
                }
                else
                {
                    var jtParent = ((JObject)jtDes)[keyDes].Parent;
                    string name = ((JProperty)clone).Name;
                    CheckNameValid(jtDes, ref name, out ErrorCode, out ErrorText);
                    value = ((JProperty)clone).Value;
                    JProperty jProperty = new JProperty(name, value);
                    jtParent.AddAfterSelf(jProperty);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "MoveToAfterDes Fail！" + ex.ToString();
            }
        }

        public void MoveToBeforeDes(string sourcePath, string desPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jtSource = GetParentToken(sourcePath, out ErrorCode, out ErrorText);
                var keySource = sourcePath.Substring(sourcePath.LastIndexOf(".") + 1);
                JToken clone = null;
                if (keySource.Contains("["))
                {
                    if (keySource.Contains(":"))
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keySource.Replace("[", "").Replace("]", "").Split(':')[1];
                        clone = ((JArray)jtSource)[index].DeepClone();
                        ((JArray)jtSource)[index].Remove();
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", ""));
                        clone = ((JArray)jtSource)[index].DeepClone();
                        ((JArray)jtSource)[index].Remove();
                    }
                }
                else
                {
                    clone = ((JObject)jtSource)[keySource].Parent.DeepClone();
                    ((JObject)jtSource)[keySource].Parent.Remove();
                }



                JToken value = null;
                JToken jtDes = GetParentToken(desPath, out ErrorCode, out ErrorText);
                var keyDes = desPath.Substring(desPath.LastIndexOf(".") + 1);
                if (keyDes.Contains("["))
                {
                    if (keyDes.Contains(":"))
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keyDes.Replace("[", "").Replace("]", "").Split(':')[1];
                        ((JArray)jtDes)[index].AddBeforeSelf(clone);
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", ""));
                        ((JArray)jtDes)[index].AddBeforeSelf(clone);
                    }
                }
                else
                {
                    var jtParent = ((JObject)jtDes)[keyDes].Parent;
                    string name = ((JProperty)clone).Name;
                    CheckNameValid(jtDes, ref name, out ErrorCode, out ErrorText);
                    value = ((JProperty)clone).Value;
                    JProperty jProperty = new JProperty(name, value);
                    jtParent.AddBeforeSelf(jProperty);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "MoveToBeforeDes Fail！" + ex.ToString();
            }

        }

        public void InsertToAfterDes(JProperty newValue, string desPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken value = null;
                JToken jtDes = GetParentToken(desPath, out ErrorCode, out ErrorText);
                var keyDes = desPath.Substring(desPath.LastIndexOf(".") + 1);
                if (keyDes.Contains("["))
                {
                    if (keyDes.Contains(":"))
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keyDes.Replace("[", "").Replace("]", "").Split(':')[1];
                        ((JArray)jtDes)[index].AddAfterSelf(newValue);
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", ""));
                        ((JArray)jtDes)[index].AddAfterSelf(newValue);
                    }
                }
                else
                {
                    var jtParent = ((JObject)jtDes)[keyDes].Parent;
                    string name = ((JProperty)newValue).Name;
                    CheckNameValid(jtDes, ref name, out ErrorCode, out ErrorText);
                    value = ((JProperty)newValue).Value;
                    JProperty jProperty = new JProperty(name, value);
                    jtParent.AddAfterSelf(jProperty);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "InsertToAfterDes Fail！" + ex.ToString();
            }
        }

        public void InsertToBeforeDes(JProperty newValue, string desPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken value = null;
                JToken jtDes = GetParentToken(desPath, out ErrorCode, out ErrorText);
                var keyDes = desPath.Substring(desPath.LastIndexOf(".") + 1);
                if (keyDes.Contains("["))
                {
                    if (keyDes.Contains(":"))
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keyDes.Replace("[", "").Replace("]", "").Split(':')[1];
                        ((JArray)jtDes)[index].AddBeforeSelf(newValue);
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keyDes.Replace("[", "").Replace("]", ""));
                        ((JArray)jtDes)[index].AddBeforeSelf(newValue);
                    }
                }
                else
                {
                    var jtParent = ((JObject)jtDes)[keyDes].Parent;
                    string name = ((JProperty)newValue).Name;
                    CheckNameValid(jtDes, ref name, out ErrorCode, out ErrorText);
                    value = ((JProperty)newValue).Value;
                    JProperty jProperty = new JProperty(name, value);
                    jtParent.AddBeforeSelf(jProperty);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "InsertToBeforeDes Fail！" + ex.ToString();
            }
        }

        private void CheckNameValid(JToken jtoken, ref string keyName, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                HashSet<string> names = new HashSet<string>();
                bool contain = false;
                foreach (var item in jtoken.Children<JProperty>())
                {
                    names.Add(item.Name);
                    if (keyName == item.Name)
                    {
                        contain = true;
                    }
                }
                if (contain)
                {
                    GetValidName(names, ref keyName, out ErrorCode, out ErrorText);
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "InsertToBeforeDes Fail！" + ex.ToString();
            }
        }

        private void GetValidName(HashSet<string> hashSet, ref string keyName, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                bool canAdd = hashSet.Add(keyName);
                if (!canAdd)
                {
                    if (keyName.Length > 50)
                    {
                        return;
                    }
                    keyName = keyName + "_copy";
                    GetValidName(hashSet, ref keyName, out ErrorCode, out ErrorText);
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "InsertToBeforeDes Fail！" + ex.ToString();
            }
        }

        private JToken GetParentToken(string keyPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                //"root.arry1.[1:array12].[1:2]"
                //"root.arry1.[0:array11].[1]"

                //判断是否为根节点
                int LastIndex = keyPath.LastIndexOf(".");

                keyPath = LastIndex != -1 ? keyPath.Substring(0, LastIndex) : keyPath;
                string[] keys = keyPath.Split('.');

                JToken jt = _jToken;
                for (int i = 0; i < keys.Length; i++)
                {
                    if (keys[i].Contains('['))  //数组
                    {
                        if (keys[i].Contains(":"))
                        {
                            string keyIndex = keys[i].Replace("[", "").Replace("]", "").Substring(0, keys[i].LastIndexOf(":") - 1);
                            string keyName = keys[i].Replace("[", "").Replace("]", "").Substring(keys[i].LastIndexOf(":"));
                            int index = int.Parse(keyIndex);
                            jt = jt[index][keyName];
                        }
                        else
                        {
                            int index = int.Parse(keys[i].Replace("[", "").Replace("]", ""));
                            jt = jt[index];
                        }
                    }
                    else  //类
                    {
                        jt = jt.SelectToken(keys[i]);
                    }
                }
                return jt;
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "InsertToBeforeDes Fail！" + ex.ToString();
                return null;
            }
        }


        public JToken GetToken(string keyPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                JToken jtSource = GetParentToken(keyPath, out ErrorCode, out ErrorText);
                int LastIndex = keyPath.LastIndexOf(".");
                //判断是否为根节点
                if (LastIndex == -1)
                {
                    return ((JObject)jtSource).Parent;
                }

                var keySource = keyPath.Substring(LastIndex + 1);
                if (keySource.Contains("["))
                {
                    if (keySource.Contains(":"))
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", "").Split(':')[0]);
                        string name = keySource.Replace("[", "").Replace("]", "").Split(':')[1];
                        return ((JArray)jtSource)[index];
                    }
                    else  //数组值
                    {
                        int index = int.Parse(keySource.Replace("[", "").Replace("]", ""));
                        return ((JArray)jtSource)[index];
                    }
                }
                else
                {
                    return ((JObject)jtSource)[keySource].Parent;
                }
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "GetToken Fail！" + ex.ToString();
                return null;
            }
        }

        public JToken GetValue(string keyPath, out int ErrorCode, out string ErrorText)
        {
            ErrorCode = 0;
            ErrorText = "NoError";
            try
            {
                var jt = GetToken("root.aaa", out _, out _);
                return ((JProperty)jt).Value;
            }
            catch (Exception ex)
            {
                ErrorCode = -1;
                ErrorText = "GetValue Fail！" + ex.ToString();
                return null;
            }
        }




    }
}
